Question about SubString in DataFrames

Hi everyone, I have a question about SubStrings. The documentation states that they are views into a parent string.

Suppose I want to clean up the following DataFrame:

df = DataFrame(type_year = [“Red 2019”, “Red 2020”, “Blue 2019”, “Blue 2020”],
value = 42)
select!(df, :type_year => ByRow(split) => [:type, :year], :value)

Then, the new columns are SubStrings, but their parent column is gone because it is no longer needed. Can this become a problem when acting on the SubString columns? Would there be any benefit in converting them to regular strings? It somehow feels “wrong” to me to have those columns be SubStrings because their former parent doesn’t have any meaning anymore.

Thanks in advance for clarifying!

Julia does garbage collection to free objects. SubString reference the source string, so even if YOU can’t access the string, it can. Therefor the GC will will not collect the source string. So you don’t need to worry about that.

1 Like